package com.ruoyi.web.controller.hotel;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.LyhmsCustomer;
import com.ruoyi.hotel.service.ILyhmsCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 * @author ruoyi
 * @date 2022-02-28
 */
@RestController
@RequestMapping("/system/customer")
public class LyhmsCustomerController extends BaseController {
    @Autowired
    private ILyhmsCustomerService lyhmsCustomerService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LyhmsCustomer lyhmsCustomer) {
        startPage();
        List<LyhmsCustomer> list = lyhmsCustomerService.selectLyhmsCustomerList(lyhmsCustomer);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LyhmsCustomer lyhmsCustomer) {
        List<LyhmsCustomer> list = lyhmsCustomerService.selectLyhmsCustomerList(lyhmsCustomer);
        ExcelUtil<LyhmsCustomer> util = new ExcelUtil<LyhmsCustomer>(LyhmsCustomer.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lyhmsCustomerService.selectLyhmsCustomerById(id));
    }

    /**
     * 新增
     */
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LyhmsCustomer lyhmsCustomer) {
        return toAjax(lyhmsCustomerService.insertLyhmsCustomer(lyhmsCustomer));
    }

    /**
     * 修改
     */
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LyhmsCustomer lyhmsCustomer) {
        return toAjax(lyhmsCustomerService.updateLyhmsCustomer(lyhmsCustomer));
    }

    /**
     * 删除
     */
    @Log(title = "", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lyhmsCustomerService.deleteLyhmsCustomerByIds(ids));
    }
}
